layui.use(['admin', 'jquery', 'layer','element'], function() {
    var $ = layui.jquery;
    var layer = layui.layer;
    var layelem = layui.element;
    var admin = layui.admin;

    // 框 架 初 始 化
    admin.render({
        "logo": {
            "title": "ERP&nbsp;" + USER_CAMPUS_NAME,
            "image": "/static/admin/images/logo.png"
        },
        "menu": {
            "data": MODULE_PATH+"admin.index/menu",
            "accordion": true,
            "control": false,
            "select": "0"
        },
        "tab": {
            "muiltTab": true,
            "keepState": true,
            "tabMax": 30,
            "index": {
                "id": "0",
                "href": MODULE_PATH+"admin.index/home",
                "title": "首页"
            }
        },
        "theme": {
            "defaultColor": "2",
            "defaultMenu": "dark-theme",
            "allowCustom": true
        },
        "colors": [{
                "id": "1",
                "color": "#FF5722"
            },
            {
                "id": "2",
                "color": "#5FB878"
            },
            {
                "id": "3",
                "color": "#1E9FFF"
            }, {
                "id": "4",
                "color": "#FFB800"
            }, {
                "id": "5",
                "color": "darkgray"
            }
        ],
        "other": {
            "keepLoad": 100
        },
        "header":{
            "message":MODULE_PATH+"admin.index/adminMessage",
        }
    });
    admin.message();

    $('.all_read').click(function () {
        layer.open({
            type: 1
            ,offset: 'auto'
            ,content: '<div style="padding: 20px 100px;">确认清空全部新消息提醒吗?</div>'
            ,btn: '确定'
            ,btnAlign: 'c' //按钮居中
            ,shade: 0 //不显示遮罩
            ,yes: function(){
                $.ajax({
                    url:MODULE_PATH+"admin.index/allRead",
                    dataType: 'json',
                    type: 'GET',
                    success: function(res) {
                        layer.close(layer.index);
                        layer.msg(res.msg);
                        $('.my-msg').remove();
                        $('.my-red-dot').removeClass('layui-badge-dot');
                    }
                })
            }
        });
    });

    layelem.on('nav(layui_nav_right)', function(elem) {

        if ($(elem).hasClass('logout')) {
            layer.confirm('确定退出登录吗?', function(index) {
                layer.close(index);
                $.ajax({
                    url: MODULE_PATH+'admin.system/logout',
                    type:"POST",
                    dataType:"json",
                    success: function(res) {
                        if (res.code==1) {
                            layer.msg(res.msg, {
                                icon: 1
                            });
                            setTimeout(function() {
                                location.href = MODULE_PATH+'login';
                            }, 333)
                        }
                    }
                });
            });
        }else if ($(elem).hasClass('password')) {
            layer.open({
                type: 2,
                maxmin: true,
                title: '修改密码',
                shade: 0.1,
                area: ['600px', '480px'],
                content:MODULE_PATH+'admin.index/pass'
            });
        }else if ($(elem).hasClass('cache')) {
            $.post(MODULE_PATH+'admin.index/cache',
            function(data){
                layer.msg(data.msg, {time: 1500});
                 location.reload()
            });

        }

    });
})
